<?php
class CateModel extends Model{
    public function getCate(){
        $tmp_data = $this->findAll();
        foreach((array)$tmp_data as $k=>$v){
            if ($v['fcid'] ==0){
                $top_cate[$v['cid']] = $v;
                unset($tmp_data[$k]);
            }
        }
        foreach((array)$top_cate as $k=>$v){
           $data[] = $v;
           foreach ((array)$tmp_data as $key=>$value){
               if ($k == $value['fcid']){
                   $value['cname'] = "&nbsp;&nbsp;&nbsp;&nbsp;|----".$value['cname'];
                   $data[]=$value;
                   unset($tmp_data['$key']);
               }
           }
        }
        return $data;
    }
    
    public function getCateList($cid){
        if(abs($cid) === 0) return false;
        //查找当前的分类;
        $tmp_data = $this->find($cid);
        //如果是不是分类,要先把主分类弄出来;
        if(abs($tmp_data['fcid']) !==0){
            $tmp_data = $this->where(array('cid'=>$tmp_data['fcid']))->find();
            $data[$tmp_data['cid']] = $tmp_data;
        }else{
            $tmp_data = $this->find($cid);
            $data[$tmp_data['cid']] = $tmp_data;
            $data[$tmp_data['cid']]['curr'] = true;
        }
        //再列出所有这个分类下所有的下级分类;
        $tmp_data = $this->where(array('fcid'=>$tmp_data['cid']))->findAll();
        foreach((array)$tmp_data as $value){
            $data[$value['cid']] = $value;
            if ($value['cid'] == $cid) $data[$value['cid']]['curr'] = true;
        }
        return $data;
    }
}
?>
